<?php
// harden it
require_once('./manager/includes/protect.inc.php');

// initialize the variables prior to grabbing the config file
$database_type = "";
$database_server = "";
$database_user = "";
$database_password = "";
$dbase = "";
$table_prefix = "";
$base_url = "";
$base_path = "";

// get the required includes
if($database_user=='') {
        if (!$rt = @include_once "manager/includes/config.inc.php") {
           exit('Could not load MODx configuration file!');
        }
}
// Setup the MODx API
define('MODX_API_MODE', true);
// initiate a new document parser
include_once(MODX_MANAGER_PATH.'/includes/document.parser.class.inc.php');
$modx = new DocumentParser;

$modx->db->connect();
$modx->getSettings();

include_once 'assets/extends/sbshop/config/config.php';

$id_image = intval($_GET['id']);
$id_options = intval($_GET['id_options']);

if (empty($id_image)&&empty($id_options)) die();

$type = $_GET['type'];

switch ($type){
    case 'small':
           $w=100;
           break;
       case 'pic':
           $w=220;
           break;
       default:
           $w=1024;
}

if (!empty($id_image)){
    $rs =$modx->db->select("*",$modx->getFullTableName("sbshop_product_images"),"id=$id_image");
    $row = (object)$modx->db->GetRow($rs);
    include_once 'assets/extends/sbshop/images/easyphpthumbnail.class.php';
    $thumb = new easyphpthumbnail;
    $thumb -> Thumbsize = $w;
    $thumb -> Createthumb($config['image_base_dir']."$row->id_product/$row->image.jpg");
}else{
    $rs =$modx->db->select("*",$modx->getFullTableName("sbshop_product_variants"),"id=$id_options");
    $row = (object)$modx->db->GetRow($rs);
    include_once 'assets/extends/sbshop/images/easyphpthumbnail.class.php';
    $thumb = new easyphpthumbnail;
    $thumb -> Thumbsize = $w;
    $thumb -> Createthumb($config['image_base_dir']."$row->id_product/options/$row->image");
}

?>
